<extend name="_layout/main"/>
<block name="head">
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/assets/css/jasny-bootstrap.min.css"/>
    <style type="text/css">
        #thumb ~ i {
            display: none !important;
        }
    </style>
</block>
<block name="content">
    <div class="page-content">
        <div class="page-breadcrumbs">
            <ul class="breadcrumb">
                <li>
                    <i class="fa fa-home"></i>
                    <a href="{:U('dashboard/index')}">系统首页</a>
                </li>
                <li>
                    <a href="javascript:;">商品管理</a>
                </li>
                <li class="active">添加商品</li>
            </ul>
        </div>
        <div class="page-body">
            <div class="row">
                <div class="col-xs-12 col-md-12">
                    <div class="widget">
                        <div class="widget-header">
                            <span class="widget-caption">添加商品</span>
                        </div>
                        <div class="widget-body">
                            <div>
                                <div class="tabbable">
                                    <ul class="nav nav-tabs" id="myTab">
                                        <li class="active">
                                            <a data-toggle="tab" href="#home" aria-expanded="true">
                                                基本信息
                                            </a>
                                        </li>
                                    </ul>
                                    <form role="form" class="form-horizontal" method="post" id="addForm"
                                          enctype="multipart/form-data">
                                        <input type="hidden" id="id" name="id" value="{$result.id}"/>
                                        <div class="tab-content">
                                            <div id="home" class="tab-pane active">
                                                <div class="form-group ">
                                                    <label for="title" class="col-sm-2 control-label no-padding-right">商品名称</label>
                                                    <div class="col-xs-2">
                                                        <input type="text" class="form-control" id="goods_name"
                                                               name="goods_name" value="{$result.goods_name}">
                                                    </div>
                                                </div>
                                                <div class="form-group ">
                                                    <label for="author" class="col-sm-2 control-label no-padding-right">商品编码</label>
                                                    <div class="col-xs-2">
                                                        <input type="text" class="form-control" id="goods_sn"
                                                               name="goods_sn" placeholder="SN:" value="{$result.goods_sn}">
                                                    </div>
                                                </div>
                                                <div class="form-group ">
                                                    <label for="source" class="col-sm-2 control-label no-padding-right">商品库存</label>
                                                    <div class="col-xs-2">
                                                        <input type="text" class="form-control" id="goods_number"
                                                               name="goods_number" value="{$result.goods_number}">
                                                    </div>
                                                </div>
                                                <div class="form-group">
                                                    <label for="category_id" class="col-sm-2 control-label no-padding-right">商品分类</label>
                                                    <div class="col-xs-2">
                                                        <select name="category_id" id="category_id"
                                                                class="form-control">
                                                            <option value="">商品分类</option>
                                                            {$category_list}
                                                        </select>
                                                    </div>
                                                </div>
                                                <div class="form-group ">
                                                    <label for="postage"
                                                           class="col-sm-2 control-label no-padding-right">邮费</label>
                                                    <div class="col-xs-2">
                                                        <div class="input-group">
                                                            <span class="input-group-addon">￥</span>
                                                            <input type="text" class="form-control" id="postage"
                                                                   name="postage" value="{$result.postage}">
                                                        </div>
                                                        <p class="help-block red">邮费，如果包邮填0，最多保留两位小数</p>
                                                    </div>
                                                </div>
                                                <div class="form-group ">
                                                    <label for="pay_balance"
                                                           class="col-sm-2 control-label no-padding-right">支付现金</label>
                                                    <div class="col-xs-2">
                                                        <div class="input-group">
                                                            <span class="input-group-addon">￥</span>
                                                            <input type="text" class="form-control" id="pay_balance"
                                                                   name="pay_balance" value="{$result.pay_balance}">
                                                        </div>
                                                        <p class="help-block red">需要支付的现金数，如果不需要支付现金，请填 0</p>
                                                    </div>
                                                </div>
                                                <div class="form-group ">
                                                    <label for="pay_integral"
                                                           class="col-sm-2 control-label no-padding-right">支付积分</label>
                                                    <div class="col-xs-2">
                                                        <input type="text" class="form-control" id="pay_integral"
                                                               name="pay_integral" value="{$result.pay_integral}">
                                                        <p class="help-block red">需要支付的积分数，如果不需要支付积分，请填 0</p>
                                                    </div>
                                                </div>
                                                <div class="form-group ">
                                                    <label for="pay_coupon"
                                                           class="col-sm-2 control-label no-padding-right">支付商品券</label>
                                                    <div class="col-xs-2">
                                                        <input type="text" class="form-control" id="pay_coupon"
                                                               name="pay_coupon" value="{$result.pay_coupon}">
                                                        <p class="help-block red">需要支付的商品券数，如果不需要支付商品券，请填 0</p>
                                                    </div>
                                                </div>
                                                <div class="form-group">
                                                    <label for="shelves"
                                                           class="col-sm-2 control-label no-padding-right">状态</label>
                                                    <div class="col-xs-2">
                                                        <select name="shelves" id="shelves" class="form-control">
                                                            <option value="1" <eq name="result['shelves']" value="1">selected="selected"</eq> >上架销售</option>
                                                            <option value="0" <eq name="result['shelves']" value="0">selected="selected"</eq> >下架</option>
                                                        </select>
                                                    </div>
                                                </div>
                                                <div class="form-group ">
                                                    <label for="sort"
                                                           class="col-sm-2 control-label no-padding-right">排序</label>
                                                    <div class="col-xs-2">
                                                        <input type="text" class="form-control" id="sort"
                                                               name="sort" value="{$result.sort}">
                                                        <p class="help-block red">排序，数字从小到大排序</p>
                                                    </div>
                                                </div>
                                                <div class="form-group">
                                                    <label for="show"
                                                           class="col-sm-2 control-label no-padding-right">显示</label>
                                                    <div class="col-sm-5">
                                                        <label class="margin-top-5 margin-left-20">
                                                            <input type="checkbox" name="recommend" value="1"
                                                                   class="colored-warning select-item" <eq name="result['recommend']" value="1">checked</eq>>
                                                            <span class="text">猜你喜欢</span>
                                                        </label>
                                                        <label class="margin-top-5 margin-left-20">
                                                            <input type="checkbox" name="hot" value="1"
                                                                   class="colored-danger select-item" <eq name="result['hot']" value="1">checked</eq>>
                                                            <span class="text">热门推荐</span>
                                                        </label>
                                                        <label class="margin-top-5 margin-left-20">
                                                            <input type="checkbox" name="newest" value="1"
                                                                   class="colored-basic select-item" <eq name="result['newest']" value="1">checked</eq>>
                                                            <span class="text">每周上新</span>
                                                        </label>
                                                    </div>
                                                </div>
                                                <div class="form-group ">
                                                    <label for="thumb" class="col-sm-2 control-label no-padding-right">封面图</label>
                                                    <div class="col-xs-4">
                                                        <div class="fileinput fileinput-new" data-provides="fileinput">
                                                            <div class="fileinput-new thumbnail"
                                                                 style="width: 260px; height: 150px;"><img src="{$result.goods_thumb}"
                                                                    data-src="{$result.goods_thumb}">
                                                            </div>
                                                            <div class="fileinput-preview fileinput-exists thumbnail"
                                                                 style="max-width: 260px; max-height: 150px;"></div>
                                                            <div> <span class="btn btn-default btn-file"><span
                                                                    class="fileinput-new">上传</span> <span
                                                                    class="fileinput-exists">重新上传</span>
																<input type="file" name="goods_thumb" id="goods_thumb">

																</span> <a href="#"
                                                                           class="btn btn-default fileinput-exists"
                                                                           data-dismiss="fileinput">删除</a></div>
                                                        </div>
                                                        <!--<span class="btn btn-default" id="selectVideo"> <a >从图库中选</a></span>-->
                                                    </div>
                                                </div>

                                                <div class="form-group">
                                                    <label for="content"
                                                           class="col-sm-2 control-label no-padding-right">商品详情</label>
                                                    <div class="col-xs-6">
                                                        <?php echo form::editor('introduce',htmlspecialchars_decode(stripslashes($result['introduce'])),'full')?>
                                                    </div>
                                                </div>
                                            </div>

                                            <div class="row">
                                                <div class="col-sm-offset-2 col-sm-10">

                                                    <button type="submit" class="btn btn-blue ladda-button"
                                                            data-style="expand-right" id="submitBtn"><span
                                                            class="ladda-label">确认保存</span></button>
                                                </div>
                                            </div>
                                        </div>
                                    </form>
                                </div>

                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</block>

<block name="footer">

    <script src="__PUBLIC__/assets/js/validation/bootstrapValidator.js" type="text/javascript" charset="utf-8"></script>
    <script src="__PUBLIC__/assets/js/select2/select2.js"></script>
    <script src="__PUBLIC__/assets/js/holder.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="__PUBLIC__/assets/js/jasny-bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="__PUBLIC__/assets/js/jquery.form.js" type="text/javascript" charset="utf-8"></script>
    <script src="/Public/assets/js/template-min.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript">
        var loader = Ladda.create(document.getElementById("submitBtn"));
        $("#addForm").bootstrapValidator({
            excluded: [':disabled'],
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            submitHandler: function (validator, form, submitButton) {
                loader.start();
                $("#addForm").ajaxSubmit(function (result) {
                    loader.stop();
                    result = JSON.parse(result);
                    if (result.status == 'success') {
                        location.href = "{:U('goods/index',['catid'=>I('catid')])}";
                    } else {
                        tips(result.message, 'danger');
                        validator.disableSubmitButtons(false);
                    }
                });
            },
            fields: {
                goods_name: {
                    validators: {
                        notEmpty: {
                            message: '商品标题不能为空'
                        }
                    }
                },
                category_id: {
                    validators: {
                        notEmpty: {
                            message: '商品分类不能为空'
                        }
                    }
                },
                goods_number: {
                    validators: {
                        notEmpty: {
                            message: '商品库存不能为空'
                        },
                        numeric: {
                            message: '库存只能是数字'
                        }
                    }
                },
                postage: {
                    validators: {
                        notEmpty: {
                            message: '该项不能为空'
                        },
                        numeric: {
                            message: '邮费只能是数字'
                        }
                    }
                },
                pay_balance: {
                    validators: {
                        notEmpty: {
                            message: '该项不能为空'
                        },
                        numeric: {
                            message: '支付现金只能是数字'
                        }
                    }
                },
                pay_integral: {
                    validators: {
                        notEmpty: {
                            message: '该项不能为空'
                        },
                        numeric: {
                            message: '支付积分只能是数字'
                        }
                    }
                },
                pay_coupon: {
                    validators: {
                        notEmpty: {
                            message: '该项不能为空'
                        },
                        numeric: {
                            message: '支付商品券只能是数字'
                        }
                    }
                }
            }
        });


    </script>
</block>